package com.keur.money.ui.main.impl

import android.content.Context
import com.keur.money.mvp.presenter.MvpPresenter
import com.keur.money.ui.main.view.IKeurRepayView
import com.keur.money.utils.helper.SharedHelper
import org.json.JSONArray
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/8/6 15:46
 * @Annotation：待还款 Presenter 实现
 */
class KeurRepayPresenterImpl(context: Context?) : MvpPresenter<IKeurRepayView>(context) {

    private var model: KeurHomeModelImpl? = null
    init {
        model = KeurHomeModelImpl()
    }

    /**
     * 加载待还款列表
     */
    fun loadMullaRepayListAction(){
        val pData = SharedHelper.getKeurSPString(SharedHelper.KEUR_SPKEY.KEUR_PRODCTS)
        val repayList = ArrayList<JSONObject>()
        if (pData.isNotEmpty()){
            val objArray = JSONArray(pData)
            for (i in 0..<objArray.length()){
                val item = objArray.optJSONObject(i)
                if (item.optString("status") != "REPAYMENT"){
                    continue
                }
                repayList.add(item)
            }
        }
        mvpView?.showMullaRepayList(repayList)
    }
}